<template>
  <uni-nav-bar :title="title+'奖'" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <view class="animation-slide-right">
    <view class="direction-start" style="background-color: #39A8FF;color:#fff;padding:30rpx;box-sizing: border-box;">
      <view>{{name}}(元)</view>
      <view style="margin-top: 5rpx;font-size: 48rpx;">{{money}}</view>
    </view>
    <scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
      :style="{ height:pageHeight + 'px'}">
      <view class="package_sale" style="padding: 10rpx 30rpx;margin: 0px;">
        <view v-for="item in orderLists" :key='item.id'  @click="show==item.id?show=0:show=item.id">
          <view class="space-between lis" >
            <view class="direction-start">
              <view class="center">{{item.memo}}<uni-icons type="top" size="20"
                  :style="{transform:show==item.id?'rotate(180deg)':'rotate(0deg)',marginLeft:'10rpx'}"
                  v-if="item.json&&item.json.length>0"></uni-icons></view>
              <view style="font-size: 26rpx;color: #666;margin-top: 6rpx;">{{item.createtime}}</view>
            </view>
            <view>
              <view>{{item.money}}</view>
            </view>
          </view>
          <view class="detail space-between" v-if="show==item.id&&item.json&&item.json.length>0">
            <view v-for="items in item.json" style="width:50%;color:#666;font-size: 26rpx;margin-top:5rpx;">{{items.name}}
              : {{items.value}}</view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import { navBack } from '@/utils/navigator';
  import { onLoad } from '@dcloudio/uni-app';
  import { getWagesLog } from '@/gql/earthPushing/attendance';
  import { toPublish } from '@mqtt';
  import { showLoading } from '@/utils/prompt';
  /**
   * 地推考勤奖励详情列表
   * @param staff_id 地推ID
   * @param type 奖励状态
   * @param name 奖励名称
   * @param money 奖励金额
   * @param orderLists 奖励列表
   * @param lastPage 总页数
   * @param currentPage 当前页数
   */
  const staff_id = ref();

  const type = ref('')
  const name = ref('')
  const money = ref('')
  const title = ref('')
  const month = ref('')
  const show = ref(0)

  const orderLists = ref([]);
  const isLoading = ref(false);
  const lastPage = ref(1);
  const currentPage = ref(1);
  const pageHeight = ref();
  uni.getSystemInfo({
    success: function (res) {
      pageHeight.value = res.windowHeight - 150;
    },
  });
  onLoad((pearm) => {
    title.value = pearm.title
    money.value = pearm.money
    type.value = pearm.type
    name.value = pearm.name
    month.value = pearm.month
    staff_id.value = Number(pearm.id)
    init()
  })
  /**
   * 获取地推奖励信息
   */
  function init() {
    showLoading()
    isLoading.value = true;
    const payload = {
      query: getWagesLog,
      variables: {
        page: currentPage.value,
        staff_id: staff_id.value,
        type: type.value,
        month: month.value
      },
    };
    toPublish(
      'ql/staff/getWagesLog',
      payload,
      (obj : any) => {
        const { getWagesLog } = obj.data;
        isLoading.value = false;
        orderLists.value = [...orderLists.value, ...getWagesLog.list];
        lastPage.value = getWagesLog.lastpage;
      },
    );
  }
  /**
   * 加载更多
   */
  function loadMore() {
    if (currentPage.value < lastPage.value) {
      currentPage.value++;
      init()
    }
  }
</script>

<style scoped lang="less">
  .lis:nth-last-of-type(1) {
    border: none;
  }

  .lis {
    border-bottom: 1px solid #eee;
    padding: 20rpx 0px;
    box-sizing: border-box;
  }

  .order {
    display: flex;
    align-items: center;
    padding: 2px 20rpx;
    box-sizing: border-box;
    margin-left: 20rpx;
    background-color: #eee;
    border-radius: 30rpx;
  }

  .detail {
    width: 100%;
    background-color: #eee;
    border-radius: 5px;
    padding: 10rpx 20rpx;
    box-sizing: border-box;
    flex-wrap: wrap;
  }
</style>
<style>
  .datas>>>.uni-date__x-input {
    font-size: 30rpx !important;
  }

  .datas>>>.uni-date-x {
    font-size: 30rpx !important;
  }

  .datas>>>.uni-icons {
    font-size: 48rpx !important;
  }
</style>